<%--
  Created by IntelliJ IDEA.
  User: 61003
  Date: 2023/3/2
  Time: 15:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>用户管理页面</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/bootstrap-theme.min.css">
    <script src="/js/jquery-1.12.4.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <style>
        body {
            background: none repeat scroll 0 0 #D8EDFC;
            margin: 0;
            padding: 0;
        }
        .page{
            margin: 20px;
        }
        .page a{
            text-decoration: none;
            padding: 5px 10px;
            cursor: pointer;
        }

        .page a:hover{
            background-color: cornflowerblue;
        }

        .page .active{
            background-color: palevioletred;
        }

    </style>
</head>
<body>
<table width="600" align="center" class="table table-striped table table-bordered">
    <caption>用户管理</caption>
    <thead>
       <th>ID</th>
       <th>用户名</th>
       <th>密码</th>
       <th>昵称</th>
       <th>手机号</th>
       <th>余额</th>
       <th width="200">操作</th>
    </thead>
    <tbody>
        <c:forEach var="user" items="${requestScope.pageBean.datas}" varStatus="v">
            <tr>
                <td>${v.index}-${user.user_id}</td>
                <td>${user.username}</td>
                <td>${user.password.charAt(0)}*****${user.password.charAt(user.password.length()-1)}</td>
                <td>${user.nick_name}</td>
                <td>${user.phone}</td>
                <td>${user.balance}</td>
                <td>
                    <a href="/users?action=update&user_id=${user.user_id}">更新</a>
                    <a onclick="deleteUser('${user.username}', ${user.user_id})">删除</a>
                </td>
            </tr>
        </c:forEach>
    </tbody>
</table>

<script>
    function deleteUser(name, id){
        if(confirm('是否确认删除'+name+"?")) {
            open('/users?action=delete&user_id='+id,'_self')
        }
    }

    onload = function () {
        if('${sessionScope.delMsg}' !== ''){
            alert('${sessionScope.delMsg}')
            fetch("/users?action=delMsg");
        }
    }
</script>
</body>
</html>
